package com.example.h.weixinui3;


import android.app.Activity;
import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.Toast;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * A simple {@link Fragment} subclass.
 */
public class FourFragment extends Fragment {



    public FourFragment() {
        // Required empty public constructor
    }

    private ListView listView_1;
    private List<Map<String,Object>> data;
    private SimpleAdapter adapter;
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // Inflate the layout for this fragment
        View view=inflater.inflate(R.layout.fragment_four, container, false);
        listView_1=(ListView)view.findViewById(R.id.listView_1);
        String[] from={"uImage","uName","uImage2"};
        int[] to={R.id.uImage,R.id.uName,R.id.uImage2};
        getData();
        adapter=new SimpleAdapter(this.getActivity(),data,R.layout.layout_fourlist,from,to);
        listView_1.setAdapter(adapter);
        return view;
    }
    private void getData(){
        data=new ArrayList<Map<String,Object>>();
        //每一项的数据
        Map<String,Object> map=new HashMap<String,Object>();
        map.put("uImage",R.drawable.a_i);
        map.put("uName","第一项");
        map.put("uImage2",R.drawable.a0z);
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("uImage",R.drawable.a_i);
        map.put("uName","第二项");
        map.put("uImage2",R.drawable.a0z);
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("uImage",R.drawable.a_i);
        map.put("uName","第三项");
        map.put("uImage2",R.drawable.a0z);
        data.add(map);

        map=new HashMap<String,Object>();
        map.put("uImage",R.drawable.a_i);
        map.put("uName","设置");
        map.put("uImage2",R.drawable.a0z);
        data.add(map);

        listView_1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Toast.makeText(getActivity(),""+position,Toast.LENGTH_SHORT).show();
                switch(position) {
                    case 3:
                        Intent intent = new Intent(getActivity(),SetActivity.class);
                        startActivity(intent);
                    //Intent intent = new Intent(getActivity(), demos[position].demoClass);
                }
            }
        });
    }


   /* private static class DemoInfo{
        private final Class<? extends android.app.Activity> demoClass;

        private DemoInfo(Class<? extends Activity> demoClass) {
            this.demoClass = demoClass;
        }
    }
    private static final DemoInfo[] demos={
            new DemoInfo(Activity.class),
            new DemoInfo(SetsActivity.class),
            new DemoInfo(SetActivity.class),
            new DemoInfo(SetActivity.class)
    };*/
}
